package com.cloudm.technician.ui.modules.personal.personal_center

import android.annotation.SuppressLint
import android.app.Dialog
import android.os.Bundle
import android.support.design.widget.BottomSheetDialog
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import com.cloudm.technician.R
import com.cloudm.technician.ui.base.BaseBottomDialogFragment
import com.cloudm.technician.ui.widget.OnceClickListener

/**
 * 作者: wesley
 * 时间: 2017/12/26
 * 描述: 底部对话框
 */
class PersonalCenterDialogFragment : BaseBottomDialogFragment() {

    var listener: OnDialogItemClickListener? = null


    companion object {

        fun newInstance() = PersonalCenterDialogFragment()
    }

    override fun handleBundle(bundle: Bundle) {

    }

    @SuppressLint("InflateParams") override fun createDialog(): Dialog {
        val view = LayoutInflater.from(mContext).inflate(R.layout.dialog_exit_login, null)
        val exitLogin = view.findViewById<TextView>(R.id.tvExitLogin)
        val exitHit = view.findViewById<TextView>(R.id.dialogExitHint)
        val exitCancel = view.findViewById<TextView>(R.id.tvCancel)

        exitLogin.setOnClickListener(OnItemClickListener())
        exitHit.setOnClickListener(OnItemClickListener())
        exitCancel.setOnClickListener(OnItemClickListener())

        return BottomSheetDialog(mContext).apply {
            setContentView(view)
        }
    }


    override fun onDetach() {
        super.onDetach()
        listener = null
    }


    interface OnDialogItemClickListener {

        fun onExitLoginClick()
    }


    inner class OnItemClickListener : OnceClickListener() {

        override fun onOnceClick(view: View) {
            dismiss()
            when (view.id) {
                R.id.tvExitLogin -> listener?.onExitLoginClick()
            }
        }
    }

}